package com.backend.demo1.controller;

import com.backend.demo1.config.ApiResponse;

import com.backend.demo1.models.Match.Comment;
import com.backend.demo1.services.MatchCommentService;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

// import java.util.List;

@RestController
@RequestMapping("/api/matchs/{matchId}/comments")
public class MatchCommentController {

    @Autowired
    private MatchCommentService matchCommentService;

    // 创建评论
    @PostMapping("/{commentId}")
    public ResponseEntity<ApiResponse<Comment>> createComment(@RequestBody Comment comment) {
        try {
            Comment createdComment = matchCommentService.createComment(comment);
            return ResponseEntity.status(HttpStatus.CREATED).body(ApiResponse.success(createdComment));
        } catch (Exception e) {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.error(400, e.getMessage()));
        }
    }


    // 根据 ID 获取评论
    @GetMapping("/{commentId}")
    public ResponseEntity<ApiResponse<List<Comment>>> getCommentById(@PathVariable Long matchId) {
        try {
            List<Comment> comment = matchCommentService.getCommentByMatchId(matchId);
            return ResponseEntity.ok(ApiResponse.success(comment));
        } catch (Exception e) {
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ApiResponse.error(404, e.getMessage()));
        }
    }


    // 删除评论
    // @DeleteMapping("/{commentId}")
    // public ResponseEntity<ApiResponse<String>> deleteComment(@PathVariable Long matchId, @PathVariable String commentId) {
    //     try {
    //         matchCommentService.deleteComment(matchId, commentId);
    //         return ResponseEntity.ok(ApiResponse.success("评论删除成功"));
    //     } catch (Exception e) {
    //         return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ApiResponse.error(500, e.getMessage()));
    //     }
    // }
}